<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>

<%@ page import ="com.easyattendance.services.AddTeacherService" %>
<%@ page import ="com.easyattendance.model.Teacher" %>
<%@ page import="com.easyattendance.services.TimeTableService" %>
<%@ page import="com.easyattendance.services.AddTeacherService" %>
<%@ page import="com.easyattendance.services.AddClassService" %>
<%@ page import="com.easyattendance.services.AddAllTimeSlotsService" %>
<%@ page import="com.easyattendance.services.AddSubjectService" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Teacher - Full Time-table</title>

<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
<jsp:include page="../includeFiles.jsp" />

<!-- pop-up modal dialog links -->

<link rel="stylesheet" href="../css/ui/jquery-ui-1.10.4.custom.min.css">
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.core.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.widget.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.position.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.dialog.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.button.js"></script>

<!-- fooTable Links -->
<link href="../css/footable.core.css" rel="stylesheet" type="text/css" />
<link href="../css/footable.metro.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/public/js/footable.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/public/js/footable.sort.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function () {
		$('.footable').footable();
	});
</script>
<script type="text/javascript">
$(function() {
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			buttons: {
				"Create an account": function() {
					console.log("create accont");
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$( "#create-user" )
			.click(function() {
				$( "#dialog-form" ).dialog( "open" );
			});
		});
</script>
</head>
<body  class="left-sidebar">

<!-- Session check : user logged in or not/ press back button -->
<jsp:include page="../common/checkSession.jsp" />
<jsp:include page="../common/checkTeacherRole.jsp" />

<% /* Get timeSlots in HashMap */
String currentUser = (String) session.getAttribute("currentUser");
AddTeacherService addTeacherService = new AddTeacherService();

AddSubjectService addSubjectService = new AddSubjectService();

AddClassService addClassService = new AddClassService();
String sectionId = addTeacherService.getSectionEmailIdByTeacherId(currentUser);
String classId = addClassService.getClassIdByTeacherId(currentUser);
TimeTableService service = new TimeTableService();
AddAllTimeSlotsService addAllTimeSlotsService = new AddAllTimeSlotsService();

String[] daysMap = service.getDaysHeader();

//Map<String, String> timeSlotsMap = new HashMap<String, String>();
String[] timeSlotsMap = addAllTimeSlotsService.listAllTimeSlotsBySection(sectionId);
String[] recessTimes = addAllTimeSlotsService.listAllRecessTimeSlots(addTeacherService.getSectionIdByTeacherId(currentUser));

boolean flag = false ;%>
			
			<div id="dialog-form" title="Create new user">
					<p class="validateTips">All form fields are required.</p>
				
					<form>
					<fieldset>
						<label for="name">Name</label>
						<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
						<label for="email">Email</label>
						<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
						<label for="password">Password</label>
						<input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
					</fieldset>
					</form>					
				</div>
				
<div id="wrapper">

		<!-- Content -->
		<div id="content">
			<div id="content-inner">
				<!-- <input type="button" id="create-user">Create new user</button> -->
				<TABLE name="timeTable" id="tbl" class="footable metro-attendance">
					
						<thead>
						<TR>
							<TH data-toggle="true" data-sort-ignore="true">  </TH>
							<% for(int i=0; i < daysMap.length ; i++) {  %>
								<TH data-toggle="true" data-sort-ignore="true"> <%= daysMap[i] %> </TH>
							<% } %>
						</TR>
						</thead>
						<tbody>
							<% for(int i=0; i <timeSlotsMap.length - 1; i++) {%>
							<TR>
								<TD> <%= timeSlotsMap[i] %> </TD>
								<% for(int j=0; j < daysMap.length; j++) {
									flag=false;
									for(int k =0; k < recessTimes.length; k++) {
										if(timeSlotsMap[i].equals(recessTimes[k])) {
											flag=true;
										}
									}
									if(flag) {%>
										<TD> RECESS </TD>
									<%} else {
											//String subjectId = service.getSubject(timeSlotsMap[i], daysMap[j], classId);
											%>
											
											<% if(service.getSubject(timeSlotsMap[i], daysMap[j], classId).equals("Free Lecture")) { %>
												<TD> Free Lecture </TD>
											<%} else {
												String subjectId = service.getSubject(timeSlotsMap[i], daysMap[j], classId);
												String tempTeacherId = service.getTeacher(timeSlotsMap[i], daysMap[j], classId);%>
											<TD> <%=addSubjectService.getSubjectBySubjectId(subjectId).getSubject_name()%><BR><%=addTeacherService.getTeacherById(tempTeacherId).getTeacher_name() %>&nbsp;<%=addTeacherService.getTeacherById(tempTeacherId).getTeacher_lname()%></TD>
											<%}%>
									<% } %>
								<% } %>
							</TR>
							<% } %>
						</tbody>
						
					
					</TABLE>
				</div>
				
			</div>
		</div>

		<!-- Sidebar -->
		<div id="sidebar">

			<!-- Sidebar Header - Logo & Name -->
			<jsp:include page="../common/sidebarHeader.jsp" />

			<jsp:include page="teacherMenu.jsp" />

			<!-- Sidebar Footer Content -->
			<jsp:include page="../common/sidebarFooter.jsp" />

		</div>

	</div>	
	<script type="text/javascript">
		$(function(){
			$("#viewFullTimeTable").addClass("current_page_item");
		});
	</script>

</body>
</html>